package com.hh.bss.common;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class Children {
	public List<Node> list = new ArrayList<Node>();
	
	public int getSize(){
		return list.size();
	}
	
	public void addChild(Node node){
		list.add(node);
    }
	
	public String toString() {
		String result = "[";
		for(Iterator<Node> it = list.iterator();it.hasNext();) {
			Node node = it.next();
			if(node.visible) {
				result += node.toString();
				result += ",";
			}
		}
		result = result.substring(0,result.length() -1);
		result += "]";
		return result;
				
	}
	public void sortChildren() {
		Collections.sort(list, new NodePriorityComparator());
		
		for(Iterator<Node> it = list.iterator(); it.hasNext();){
			it.next().sortChildren();
		}
	}
	
	public void setTreeVisible() {
		for(Iterator<Node> it = list.iterator();it.hasNext();){
			it.next().setTreeNotVisible();
		}
	}
	
	public void setTreeNotVisible() {
		for (Iterator<Node> it = list.iterator(); it.hasNext();){
			it.next().setTreeNotVisible();
		}
	}

	public void initializeLeafList(List<Node> leafList) {
		for(Iterator<Node> it = list.iterator();it.hasNext();){
			it.next().initializeLeafList(leafList);
		}
		
	}

}
